<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
</head>
<body>
<form class="layui-form" action="" lay-filter="edit">
    <div class="mainBox">
        <div class="main-container">

                                <!-- id隐藏列 -->
                    <div class="layui-form-item layui-hide">
                        <label class="layui-form-label">id</label>
                        <div class="layui-input-block">
                            <input type="text" name="commTypeId">
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">类型名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="commTypeName" lay-verify="title|required" autocomplete="off"
                                   placeholder="请输入"
                                   class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">类型备注</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入备注" name="commTypeRemark" class="layui-textarea" utocomplete="off" maxlength="80"></textarea>
                        </div>
                    </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit lay-filter="type-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>

<script>
    // layui.use(['easyAdmin'], function () {
    //     let easyAdmin = layui.easyAdmin;
    //     easyAdmin.FormVal(uri);
    //     easyAdmin.FormSave(uri);
    // })

    layui.use(['form', 'jquery', 'easyAdmin'], function () {
        let uri = "/comm/type";
        let form = layui.form;
        let $ = layui.jquery;
        let easyAdmin = layui.easyAdmin;
        var id;

        id = easyAdmin.getQueryString("id");
        easyAdmin.http({
            url: '/comm/type/' + id,
            dataType: 'json',
            contentType: 'application/json',
            type: 'get',
            success: function (result) {
                if (result.success) {
                    //表单数据回显
                    form.val("edit", result.data);
                } else {
                    layer.msg(result.msg, {icon: 2, time: 1000});
                }
            }
        });

        form.on('submit(type-save)', function (data) {
            data.field.commTypeId = id;

            easyAdmin.http({
                url: uri,
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000, area: ['100px', '80px']}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000, area: ['260px', '80px']});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>
